<?php

namespace App\Dao\Ocean;

use Yj\Daos\BaseDaos;
use App\Model\Ocean\OceanUserFish;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var OceanUserFish
 * @method $this params($params)
 */
class OceanUserFishDao extends BaseDaos
{
    public function searchParams(Collection $params)
    {
        $search = $this->getSearch();
        $params->check('user_id', function ($user_id) use ($search) {
            $search->where('user_id', $user_id);
        });
        $params->check('status', function ($status) use ($search) {
            $search->where('status', $status);
        });
        return $search;
    }

    public function lists(Collection $params)
    {
        $data = $this->params($params)->with(['OceanFish' => function ($query) {
            $query->with('picture');
        }])->orderByDesc("id")->getList();
        return $data;
    }

    public function add(Collection $params)
    {

        $data = $this->create($params->toArray());
        return $data;

    }

    public function del(int $id)
    {

        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        return $data->delete();

    }
}
